﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Dryricenet
{
    public partial class Leave : System.Web.UI.Page
    {
        public int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Name"] == null)
            {
                //登录状态为空
                Response.Write("<script>javascript:alert('对不起,您还没有登录!');history.back();</script>");
                Response.End();
            }
            else
            {
                string name = Session["Name"].ToString();
                DataTable dt = userBLL.selectNameBll(name);
                DataRow dr = dt.Rows[0];//第一条数据
                id = Convert.ToInt32(dr["UserID"]);
                txtName.Text = dr["UserName"].ToString();
            }
        }
        //提交留言
        protected void Button1_Click(object sender, EventArgs e)
        {
           Models.Leave l = new Models.Leave();
            l.Title = txtTitle.Text.Trim();
            l.Content = txtContent.Text.Trim();
            l.Time = DateTime.Now;
            l.UserID = id;
            if (LeaveBLL.leaveAddBLL(l))
            {
                Response.Write("<script>javascript:alert('亲！感谢您对我们的支持');history.back();</script>");
                Response.End();
            }
            else {
                Response.Write("<script>javascript:alert('添加失败！');history.back();</script>");
                Response.End();
            }
        }
    }
}